#!/usr/bin/env python

from iwin.db import PG
from iwin.spider.stock.dividend.hk.aastocks import fetch as _fetch


def fetch_hk(code_id, code):
    code = str(code).rjust(5, '0')
    table = 'stock.event'
    for day, action, txt in _fetch(code):
        print(day, action, txt)
        d = dict(code_id=code_id, day=day, action=action)
        if not PG.select_one(table, d):
            d['txt'] = txt
            PG.insert(table, d)


dividend = dict(HK=fetch_hk)

if __name__ == "__main__":
    import single_process.init
    fetch_hk(656)
